<?php
namespace app\staff\controller;
use app\BaseController;
use app\staff\model\StaffPeople;
use think\Request;

class Index extends BaseController
{
    /**员工登录
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function sign_in(Request $request){
        $data = $request->param();
        $array = [
            'phone|用户手机号码'=>'require|mobile',
            'pwd|密码'=>'require',
        ];
        $this->validate($data,$array);
        $user = StaffPeople::where('status',1)
            ->withoutField('delete_time,sort,status')
            ->where('phone',trim($data['phone']))
            ->find();
        if(empty($user)){
            return api_fail('账号不存在');
        }
        if($user->getData('pwd')!=password(trim($data['pwd']))){
            return api_fail('账号或密码错误');
        }
        $user = $user->toArray();
        unset($user['pwd']);
        $user['token'] = StaffPeople::getToken($user['id']);
        return api_success('获取成功',$user);
    }

    /**获取照护师协议
     * @return \think\response\Json
     */
    public function get_staff_xieyi(){
        $data = sysconfig('agreement','zhaohushixieyi');
        return api_success('获取成功',['text'=>$data]);
    }
}